﻿using ConfExpert.Forms.Base;
using DevExpress.XtraBars;
using DevTeam;
using System;
using System.Data;

namespace ConfExpert.Forms.Depo.Aksesuar
{
    public partial class UreticiMail : XForm
    {
        public UreticiMail()
        {
            InitializeComponent();
        }

        private void ModelDetaylari_Load(object sender, EventArgs e)
        {

            this.Text = "Tedarikçi Mailleri";
            gvModel.Init("GetVendorMails");

            gvModel.AddAutoIncrementalPK("VendorMailId");
            gvModel.MakeColumnInvisible("VendorMailId");
            gvModel.SetCaptions("VendorId:Tedarikci");
            gvModel.EnableRowDelete();

            gvModel.BestFitColumns();

            gvModel.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

            DataTable dt = gvModel.Dataset().Tables[1];
            bool powerUser = (dt.Select("UserId=" + WhoAmI).Length > 0);
            bbiSave.Visibility = powerUser ? BarItemVisibility.Always : BarItemVisibility.Never;
            bbiSave.ItemClick += bbiSave_ItemClick;
        }

        void bbiSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvModel.EndEditing();
            int BosMail = gvModel.DataTable().Select("Isnull(Mail,'')=''").Length;
            if (BosMail > 0)
            {
                ShowErrorMessage("Lütfen Mail bilgisini boş bırakmayın !");
                return;
            }
            if (gvModel.Dataset().HasChanges())
            {
                gvModel.Update();
            }
            gvModel.RefreshDataSource("GetVendorMails");
            gvModel.BestFitColumns();

        }
    }
}